﻿var vm = this.lookupViewModel();
var viewStatus = this.lookupController().analysis().status;
var isInquiryCall = vm.get('NebulogyForm.isInquiryCall') || 0;

ref.costCategory.setHidden(newValue == 'LRE');
ref.BrandAllocationJLRC.setHidden(newValue == 'LRE');
ref.BrandAllocationCJLR.setHidden(newValue == 'LRE');
ref.companySharingRatioTips.setHidden(newValue == 'LRE');

if (self.containsFocus) {

    var obj = {
        UKCrossCharge: '',
        PRType: '',
        costCategory: '',
        CIP: '',
        UKGLCode: '',
        UKCostCenter: '',
        VSVCheck: '',
        Check: '',
    };

    vm.set('NebulogyForm.FinanceInformation', obj);
    ref.SharingPrinciple.hide();
    ref.SharingPrinciple.setValue('');

    ref.datagrid2.store.removeAll();
    ref.datagrid3.store.removeAll();
    ref.datagrid4.store.removeAll();
    ref.datagrid5.store.removeAll();

    ref.datagrid3.getColumns()[0].getEditor().store.data.removeAll();
    ref.datagrid4.getColumns()[0].getEditor().store.data.removeAll();
    ref.datagrid5.getColumns()[0].getEditor().store.data.removeAll();
}

if ((viewStatus == 'launch' || viewStatus == 'resubmit') && isInquiryCall == 0) {
    Ext.each(ref.UKCrossCharge.items.items, function (ctr) {
        ctr.setReadOnly(false);

        if (self.containsFocus) {
            ctr.setValue(false);
        }

        if (newValue == 'LRE') {
            ctr.setReadOnly(ctr.inputValue != 'No');

            if (ctr.inputValue == 'No' && self.containsFocus) {
                ctr.setValue(true);
            }
        }
    });
}